// let big = document.querySelector('.big')
// big.addEventListener('click',function(e){
//     e = e || window.event;
//     var target = e.target ||e.srcElement;
//     if(target.className == 'button'){
//         let user = document.querySelector('.phone')
//         let pass = document.querySelector('.passwordd')
//         console.log(user,pass)
//         console.log(1)
//     }
// })


        //注册
        let user = document.querySelector('.phone')
        let pass = document.querySelector('.password')
        let pass2 = document.querySelector('.password2')
        let btn = document.querySelector('.button')

        let reg1 = document.querySelector('.register1')
        let reg2 = document.querySelector('.register2')
        let reg3 = document.querySelector('.register3')
        let reg4 = document.querySelector('.register4')
        let reg5 = document.querySelector('.register5')

        let telreg = /^1[3-9][0-9]{9}$/    //手机号码验证
        let passreg = /^[a-zA-Z]\w{5,17}$/   //密码验证

        let num1 = false
        let num2 = false
        let num3 = false
        
        // 验证手机号
        user.onchange = function(){
            if(!user.value){
                reg2.style.display = 'none'
            }else{
                if(telreg.test(user.value)){
                    reg2.style.display = 'block'
                    reg2.innerHTML = '√'
                    return num1 = true
                }else{
                    reg2.innerHTML = '手机号不正确'
                    reg2.style.display = 'block'
                }
            }
        }

        // 验证密码
        pass.onchange = function(){
            if(pass.value){
                if(passreg.test(pass.value)){
                    reg1.style.display = 'none'
                    reg4.style.display = 'block'
                    reg4.innerHTML = '√'
                    return num2 = true
                }else{
                    reg4.innerHTML = '密码格式不正确'
                    reg1.style.display = 'none'
                    reg4.style.display = 'block'
                }
            }else{
                reg4.innerHTML = '(以字母开头，长度在6~18之间，只能包含字母、数字和下划线)'
                reg4.style.display = 'none'
                reg1.style.display = 'block'
            }
        }


        pass2.onchange = function(){
            if(pass.value == pass2.value){
                reg5.style.display = 'block'
                reg5.innerHTML = '√'
                return num3 = true
            }else{
                reg5.innerHTML = '两次密码不一致'
                reg5.style.display = 'block'
            }
        }

        btn.onclick = function(){        
            if(num1&&num2&&num3){
                    let username = {
                        user:user.value,
                        pass:pass.value
                    }
                    let list = JSON.parse(localStorage.getItem('DELL')) || []
                    if(!list.length){
                        list.push(username)
                        localStorage.setItem('DELL', JSON.stringify(list))
                        alert('注册成功！')
                        window.location.href="../html/login.html";        
                    }else{
                        let res = list.some(item=>{return item.user == username.user})
                        if(res){
                            reg2.innerHTML = '手机号已被注册'
                            reg2.style.display = 'block'
                        }else{
                            list.push(username)
                            localStorage.setItem('DELL', JSON.stringify(list))
                            alert('注册成功！')
                            window.location.href="../html/login.html";        
                        }
                    }

            }else{
                alert('请输入用户名和密码!')
            }

        }

        
